//-------------------------------------------------------------------
//	Copyright (c) 2010-2012 Zhirnov Andrey
//	This file is part of the "UXGEN" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#ifndef _UX_PROGRAM_TEXTURES_H
#define _UX_PROGRAM_TEXTURES_H

#include "../Shaders/CShaderProgram.h"
#include "../Textures/CTexture.h"
#include "IBaseMaterial.h"

namespace Engine
{
namespace Resources
{
	
	struct TTextureInit
	{
		string				sName;	// uniform name or address
		e_texture::type		eType;
		e_tex_flags::type	eFlags;	// sampler flags
		///
		TTextureInit(): sName(), eType(e_texture::UNKNOWN), eFlags(e_tex_flags::UNKNOWN) {}
		TTextureInit(const char *name, e_texture::type type, e_tex_flags::type flags): sName(name), eType(type), eFlags(flags) {}
	};
	_CREATE_META_OBJECT_FD( TTextureInit );
	

	struct TUniformTexture
	{
		GLenum			eTarget;
		GLuint			uLocation;
		uint			uSamplerID;
		e_texture::type	eType;
		uint8			uStage;
		///
		TUniformTexture(): eTarget(0), uLocation(-1), eType(e_texture::UNKNOWN), uStage(-1), uSamplerID(0) {}
		TUniformTexture(GLenum target, GLuint loc, e_texture::type type, uint samp, uint8 stage):
			eTarget(target), uLocation(loc), eType(type), uStage(stage), uSamplerID(samp) {}
	};
	
	typedef array< TUniformTexture >	uniform_textures_t;



	//
	// Program Textures
	//

	class CProgramTextures : public CEngBaseObject
	{
	private:
		array< TUniformTexture >	_aTex;
		
	private:
		CProgramTextures(const CProgramTextures &)	{}
		void operator = (const CProgramTextures &)	{}

	public:
		CProgramTextures();
		~CProgramTextures();

		bool  Create(const CShaderProgramPtr &pShader, const array<TTextureInit> &aInit);
		void  Copy(CProgramTextures &sPT);
		void  Destroy();

		void  LinkTextures(texture_array_t &aTextures, uint &uActiveTextures);
		void  GetLinkTextures(texture_array_t &aTextures);
		uint8 GetStage(e_texture::type eType);
		
		static GLenum s_ConvertSamplerToTarget(GLenum eSamplerType);
		static GLenum s_ConvertTargetToSampler(GLenum eTarget);

		// CEngBaseObject //
		virtual void Release();
	};

//-------------------------------------------------------------------

}	// Resources
}	// Engine

#endif	// _UX_PROGRAM_TEXTURES_H